package com.zhouyu.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author by gang.Li 2022/3/29 0:00
 */
@Component
public class BeanLifeTest implements MergedBeanDefinitionPostProcessor {
//	@Override
//	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
//		System.out.println("初始化前的后置处理器执行。。。。。。。。。。。。。");
//		return InstantiationAwareBeanPostProcessor.super.postProcessBeforeInstantiation(beanClass, beanName);
//	}
//
//	@Override
//	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
//		System.out.println("初始化后的后置处理器执行。。。。。。。。。。。。。");
//		return InstantiationAwareBeanPostProcessor.super.postProcessAfterInstantiation(bean, beanName);
//	}

	@Override
	public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
		if (beanName.equals("userService")) {
			beanDefinition.setInitMethodName("testApplyMergedBeanDefinitionPostProcessors");
//			beanDefinition.getPropertyValues().addPropertyValue("orderService", new OrderService());
		}
	}
}
